package com.abu.manager.controller;

import com.abu.common.Resp;
import com.abu.manager.pojo.ManagerRole;
import com.abu.manager.service.ManagerRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 阿布
 * @since 2021-02-05
 */
@RestController
@RequestMapping("manager/manager-role")
public class ManagerRoleController {

    @Autowired
    private ManagerRoleService managerRoleService;

    @PostMapping("addRolePermission")
    public Resp addRolePermission(@RequestBody ManagerRole managerRole) {
        Long managerId = managerRole.getManagerId();
//        删除已经存在的数据
        this.managerRoleService.remove(new QueryWrapper<ManagerRole>().eq("manager_id", managerId));
        boolean flag = this.managerRoleService.save(managerRole);
        if (flag) {
            return Resp.ok().msg("更新成功");
        }
        return Resp.error().msg("更新失败");
    }

}

